#include "front/text_normalize.h"

using namespace std;
using namespace ppspeech;

void TextNormalizer::SetUseLanguage(wstring* fpInWsentence, string fInLanguageName)
{
	LanguageEnum tInLanguage = LANG_ZH;
	transform(fInLanguageName.begin(), fInLanguageName.end(), fInLanguageName.begin(), ::tolower);		//大写转小写

	if(fInLanguageName == "zh") {
		tInLanguage = LANG_ZH;
	}
	else if(fInLanguageName == "en") {
		tInLanguage = LANG_EN;
	}
	else {
		tInLanguage = GetAutoLanguageEnum(*fpInWsentence);
	}
	mUseLanguage = tInLanguage;
}

LanguageEnum TextNormalizer::GetAutoLanguageEnum(wstring fInWsentence)
{
	const wregex mcWregex(L"([\\u4e00-\\u9fa5]+)");
	wsmatch tWsmatch;

	//WstrReplace(fInWsentence, "$", "");
	
	if(regex_search(fInWsentence, tWsmatch, mcWregex) )
	{
		return LANG_ZH;
	}
	return LANG_EN;
}
